﻿using Microsoft.Graphics.Canvas;
using Microsoft.Graphics.Canvas.Effects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using 纸片人.InterfaceFolder;
using 纸片人.Shaders;

namespace 纸片人.win2dEffectControl.DataClass
{
    public class WaveEffectData : PixelShaderEffectData
    {

        #region
        private float wavelengthX;
        private float wavelengthY;
        private float amplitudeX;
        private float amplitudeY;



        #endregion

        public override ShaderType shaderShaderPath { get; } = ShaderType.Wave;
        public float WavelengthX { get => wavelengthX; set { wavelengthX = value; OnPropertyChanged();SetIsChanges(); } }
        public float WavelengthY { get => wavelengthY; set { wavelengthY = value; OnPropertyChanged(); SetIsChanges(); } }
        public float AmplitudeX { get => amplitudeX; set { amplitudeX = value; OnPropertyChanged(); SetIsChanges(); } }
        public float AmplitudeY { get => amplitudeY; set { amplitudeY = value; OnPropertyChanged(); SetIsChanges(); } }

        public override ICanvasImage GetEffect(CanvasDevice device, bool compression)
        {
            var source = GetSourceEffect(device, compression);
            if (source == null)
                return null;
            if (shaderCodeBytes == null)
                return null;

            var effect = new PixelShaderEffect(shaderCodeBytes);
            effect.Source1 = source;

            effect.SetFloat("wavelengthX", WavelengthX/100f);
            effect.SetFloat("wavelengthY", WavelengthY/100f);
            effect.SetFloat("amplitudeX", AmplitudeX/100f);
            effect.SetFloat("amplitudeY", AmplitudeY/100f);
            effect.SetFloat2("size", new System.Numerics.Vector2((float)Size.Width, (float)Size.Height));
            return effect;
        }
    }
}
